﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_UpdateClientInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 35)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            Client client = ClientManager.FindByClientId(Convert.ToInt32(Request.QueryString["cid"]));
            txtClientName.Text = client.ClientName;
            txtSellUser.Text = client.SellUser.UserName;
            ddlIsShare.SelectedValue = client.IsShare.ToString();
            txtTelephone.Text = client.Telephone;
            txtFaxes.Text = client.Faxes;
            txtURL.Text = client.Url;
            txtEmail.Text = client.Email;
            txtAddress.Text = client.Address;
            txtPostalcode.Text = client.Postalcode;
            txtRemark.Text = client.Remark;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Client client = new Client();
        client.ClientId = Convert.ToInt32(Request.QueryString["cid"]);
        client.ClientName = txtClientName.Text.Trim();
        client.Address = txtAddress.Text;
        client.Email = txtEmail.Text;
        client.Faxes = txtFaxes.Text;
        client.IsShare = Convert.ToInt32(ddlIsShare.SelectedValue);
        client.Postalcode = txtPostalcode.Text;
        client.Remark = txtRemark.Text;
        client.Telephone = txtTelephone.Text;
        client.Url = txtURL.Text;
        if (ClientManager.UpdateClientById(client))
        {
            Response.Redirect("ClientList.aspx?pageIndex=" + Request.QueryString["pageIndex"]);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('编辑失败！请重试！');window.location('AddClient.aspx');</script>");
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("ClientList.aspx?pageIndex=" + Request.QueryString["pageIndex"]);
    }
}
